package com.degon.hsyl.customchatapp.ui;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.degon.hsyl.customchatapp.R;
import com.degon.hsyl.customchatapp.adapter.LinkmanListAdapter;
import com.degon.hsyl.customchatapp.bean.Linkman;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class LinkmanListActivity extends AppCompatActivity {

    private String senderId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linkman_list);

        List<Linkman> allUser = LitePal.findAll(Linkman.class);
        List<Linkman> linkmanList = new ArrayList<>();
        senderId = this.getIntent().getStringExtra("userId");
        for (Linkman linkman : allUser) {
            if (!linkman.getUserId().equals(senderId)) {
                linkmanList.add(linkman);
            }
        }

        RecyclerView listView = findViewById(R.id.联系人列表);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        listView.setLayoutManager(manager);
        LinkmanListAdapter adapter = new LinkmanListAdapter(linkmanList, this, senderId);
        listView.setAdapter(adapter);

        ImageView backBtn = findViewById(R.id.联系人页_返回按钮);
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}